<?php

namespace app\models;


use Yii;

class SyncTable
{
    /**
     * 查询产品分类表信息
     * @param string $institution_code
     * @return array|null
     */
    public static function getGoodsCategory($institution_code)
    {
        $result = null;
        if ($institution_code != null && $institution_code != '') {

            //查询SQL
            $sql = "select * from t_goods_category where institution_code=:institution_code ";

            //创建查询
            $cmd = \Yii::$app->db->createCommand($sql);
            $cmd->bindValue(':institution_code', $institution_code);

            //执行获取结果
            $result = $cmd->queryAll();
        }

        return $result;
    }

    /**
     * 获取某个机构所有的商品信息
     * @param $institutionCode
     * @return array
     */
    public static function getGoods($institutionCode)
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_goods WHERE institution_code=:institutionCode');
        $cmd->bindValue(':institutionCode', $institutionCode);
        $items = $cmd->queryAll();
        return $items;
    }

    /**
     * 获取商品分类与商品关联关系表
     * @param $institutionCode
     * @return array
     */
    public static function getGoodsCategoryGoods($institutionCode)
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_goods_category_goods WHERE institution_code=:institutionCode');
        $cmd->bindValue(':institutionCode', $institutionCode);
        $items = $cmd->queryAll();
        return $items;
    }

    /**
     * 获取商品详情信息
     * @param $institutionCode
     * @return array
     */
    public static function getGoodsDetailHtml($institutionCode)
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_goods_detail_html WHERE institution_code=:institutionCode');
        $cmd->bindValue(':institutionCode', $institutionCode);
        $items = $cmd->queryAll();
        return $items;
    }

    public static function getGoodsExtendCategory($institutionCode)
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_goods_extend_category WHERE institution_code=:institutionCode AND is_delete=0');
        $cmd->bindValue(':institutionCode', $institutionCode);
        $items = $cmd->queryAll();
        return $items;
    }

    public static function getGoodsExtendCategoryGoodsByCategory($extendCategoryId)
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_goods_extend_category_goods WHERE extend_category_id=:extendCategoryId');
        $cmd->bindValue(':extendCategoryId', $extendCategoryId);
        $items = $cmd->queryAll();
        return $items;
    }

    public static function getGoodsImage()
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_goods_image');
        $items = $cmd->queryAll();
        return $items;
    }

    public static function getAd($institutionCode)
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_ad WHERE institution_code=:institutionCode');
        $cmd->bindValue(':institutionCode', $institutionCode);
        $items = $cmd->queryAll();
        return $items;
    }

    public static function getAdCategory($institutionCode)
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_ad_category WHERE institution_code = \'0\' OR institution_code=:institutionCode');
        $cmd->bindValue(':institutionCode', $institutionCode);
        $items = $cmd->queryAll();
        return $items;
    }

    public static function getActivityBargain($institutionCode)
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_activity_bargain WHERE institution_code=:institutionCode AND is_enabled=1 AND is_deleted=0');
        $cmd->bindValue(':institutionCode', $institutionCode);
        $items = $cmd->queryAll();
        return $items;
    }

    public static function getActivityBargainGoods($institutionCode)
    {
        $cmd = Yii::$app->db->createCommand('SELECT * FROM t_activity_bargain_goods WHERE institution_code=:institutionCode');
        $cmd->bindValue(':institutionCode', $institutionCode);
        $items = $cmd->queryAll();
        return $items;
    }
}